<template>
	<view class="category-manage">
		<scroll-view class="category-manage-view" scroll-y>
			<view class="category-manage-list" v-if="categoryList.length">
				<view class="category-item" v-for="(data,index) in categoryList" :key="index" @click="goAdd(data.platform_class_id)">
					<view class="category-item-name">{{data.class_name}}</view>
					<view class="category-item-right">
						<view class="category-item-number" v-if="!manage">{{data.count}}件商品<image src="https://master.shengejiaju.cn/web/static/icons/ico_more_goods@2x.png"></image></view>
						<view class="category-item-action" v-else>
							<view class="del" @click.stop="del(data.class_id)">删除</view>
							<view class="up" @click.stop="up(data.class_id)" v-if="data.status==2">上架</view>
							<view class="down" @click.stop="down(data.class_id)" v-else>下架</view>
						</view>
					</view>
				</view>
			</view>
			<nothing :text="'还未添加分类'" :btn="false" v-else></nothing>
		</scroll-view>
		<view class="category-manage-bottom">
			<view v-if="!manage" @click="edit()"><image src="https://master.shengejiaju.cn/web/static/icons/ico_add@2x.png"></image>添加分类</view>
			<view v-if="!manage && categoryList.length" @click="manageFun"><image src="https://master.shengejiaju.cn/web/static/icons/ico_edit@2x.png"></image>管理分类</view>
			<view class="complete" @click="complete" v-if="manage">完成</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				allChecked: false,
				proPage: 0,
				manage: false,
				noMorePro: false,
				categoryList: [],
				ProList: [],
				choseList: [],
				class_id: '',
				searchValue: ''
			};
		},
		onLoad(options) {
			
		},
		onShow() {
			this.init()
		},
		methods:{
			// 初始化分类列表
			init(){
				let data = {
					status: 1,
					limit: 100,
					store_id: JSON.parse(uni.getStorageSync('userInfo')).store_id
				}
				this.$api.PlatformLists(data).then(res => {
					this.categoryList = res.datas
				})
			},
			// 添加删除分类
			edit(){
				uni.navigateTo({
					url: '/pages/platform-goods/platform-goods-style'
				})
			},
			// 删除分类
			del(id){
				let _this = this
				uni.showModal({
					content: '是否删除此分类？',
					success(res) {
						if(res.confirm){
							_this.$api.PlatformDelate({class_id: id}).then(res => {
								uni.showToast({
									icon: 'none',
									title: '删除成功',
									duration: 1500
								})
								setTimeout(() => {
									_this.init()
								},1500)
							})
						}
					}
				})
			},
			// 上架分类
			up(id){
				let _this = this
				uni.showModal({
					content: '是否上架此分类？',
					success(res) {
						if(res.confirm){
							_this.$api.UpGoodsClass({class_id: id,status: 1}).then(res => {
								uni.showToast({
									icon: 'none',
									title: '已上架',
									duration: 1500
								})
								setTimeout(() => {
									_this.init()
								},1500)
							})
						}
					}
				})
			},
			// 下架分类
			down(id){
				let _this = this
				uni.showModal({
					content: '是否下架此分类？',
					success(res) {
						if(res.confirm){
							_this.$api.UpGoodsClass({class_id: id,status: 2}).then(res => {
								uni.showToast({
									icon: 'none',
									title: '已下架',
									duration: 1500
								})
								setTimeout(() => {
									_this.init()
								},1500)
							})
						}
					}
				})
			},
			manageFun(){
				this.manage = true
			},
			complete(){
				this.manage = false
			},
			goAdd(id){
				uni.navigateTo({
					url: '/pages/platform-goods/platform-goods?type='+id
				})
			}
		}
	}
</script>

<style lang="scss">
	@import  '../../static/scss/category-manage.scss';
	.search-bar{
		border-top: solid 1px #EEE;
		border-bottom: solid 1px #EEE;
	}
	.selectView{
		position: absolute;
		top: 110rpx;
		bottom: 90rpx;
		.proList-item{
			padding: 20rpx;
			border-bottom: solid 1px #EEE;
			label{
				display: flex;
				align-items: center;
			}
			&:last-child{
				border-bottom: none;
			}
			image{
				width: 220rpx;
				height: 220rpx;
			}
			.proList-item-info{
				flex: 1;
				min-width: 0;
				margin-left: 20rpx;
				.proList-item-info-tit{
					font-size: 34rpx;
					height: 88rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.proList-item-info-price{
					font-size: 26rpx;
					color: #333;
					margin-top: 10rpx;
				}
				.proList-item-info-counts{
					font-size: 26rpx;
					color: #999;
					margin-top: 10rpx;
				}
			}
		}
	}
	.radioChange{
		margin-bottom: 30rpx;
		font-size: 24rpx;
		label{
			margin-right: 20rpx;
		}
	}
	.category-manage-view{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 98rpx;
	}
	.all-chose{
		position: fixed;
		bottom: 0;
		left: 0;
		height: 90rpx;
		right: 0;
		background-color: #FFF;
		display: flex;
		align-items: center;
		border-top: solid 1px #EEE;
		justify-content: space-between;
		padding: 0 20rpx;
		.confim-add{
			font-size: 34rpx;
			color: #2073F5;
		}
	}
</style>